package com.atguigu.gmall.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.gmall.feign.ApiBaseCategoryViewFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/***
 * 商城首页的controller层
 */
@Controller
@RequestMapping("/page/index")
public class IndexController {

    @Autowired
    private ApiBaseCategoryViewFeign apiBaseCategoryViewFeign;

    @GetMapping
    public String index(Model model){
        //1 远程调用接口
        List<JSONObject> jsonObjects = apiBaseCategoryViewFeign.listCategory();

        //2 将数据存入请求域
        model.addAttribute("categoryList",jsonObjects);

        //返回页面
        return "index";
    }
}
